package com.lexin.engine.hive.udf;

import org.apache.hadoop.hive.ql.exec.UDF;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: letu
 * @description:
 * @author: XL.Gao
 * @create: 2021-01-18 09:19
 **/
public class TMHiveUDF extends UDF {

    private static Map<String, String> map = new HashMap<>();

    static {
        synchronized (map){
            if(map == null || map.size() == 0){
                map.put("0", "Q");
                map.put("1", "W");
                map.put("2", "E");
                map.put("3", "R");
                map.put("4", "T");
                map.put("5", "Y");
                map.put("6", "U");
                map.put("7", "H");
                map.put("8", "K");
                map.put("9", "P");
            }
        }
    }

    public String evaluate(String input){

        StringBuffer sb = new StringBuffer();

        if(input != null && !"".equals(input)){
            char[] nums = input.toCharArray();

            for(char num : nums){
                sb.append(map.get(String.valueOf(num)));
            }
        }

        return sb.toString();
    }

    public String role(){

        return map.toString();
    }

    public static void main(String args[]){

        TMHiveUDF TMHiveUDF = new TMHiveUDF();
        String tfString = TMHiveUDF.evaluate("18561808500");
        System.out.println(tfString);
        System.out.println(TMHiveUDF.role());
    }
}
